// browser detect
var browserDetect = function(){
	// user agent
	this.ua = navigator.userAgent.toLowerCase();
	// version
	this.isIE = ( (this.ua.indexOf("msie") != -1) && (this.ua.indexOf("opera") == -1) && (this.ua.indexOf("webtv") == -1) );
	this.isMozilla   = (this.isGecko && this.ua.indexOf("gecko/") + 14 == this.ua.length);
	// minor version
	this.versionMinor = parseFloat(navigator.appVersion);
	// correct version number for IE4+
	if(this.isIE && this.versionMinor >= 4){ this.versionMinor = parseFloat( this.ua.substring( this.ua.indexOf('msie ') + 5 ) ); }
	// platform
	this.isWin   = (this.ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && ( this.ua.indexOf('95') != -1 || this.ua.indexOf('98') != -1 || this.ua.indexOf('nt') != -1 || this.ua.indexOf('win32') != -1 || this.ua.indexOf('32bit') != -1) );
	this.isMac   = (this.ua.indexOf('mac') != -1);
	this.isUnix  = (this.ua.indexOf('unix') != -1 || this.ua.indexOf('linux') != -1 || this.ua.indexOf('sunos') != -1 || this.ua.indexOf('bsd') != -1 || this.ua.indexOf('x11') != -1)
}
// initiate browsercheck object
var browser = new browserDetect();

//using ajaxslt lib
if(typeof(xpathParse) == "function"){
	// xPath
	var xPath = function(oNodes, sXPath){
		if(oNodes != null){
			var result = xpathParse(sXPath).evaluate(new ExprContext(oNodes));
			if(result.booleanValue() == true) return result.value;
			else return false;
		} else return false;
	}

	// xml to string translator using XMLSerializer
	var xml2str = function(src){
		if(src.nodeType >= 2 && src.nodeType <= 4) return src.nodeValue;
		else return xmlText(src);
	}
	
	// access to xPath object
	var xPathObject = function(oNodes, sXPath){
		return xpathParse(sXPath).evaluate(new ExprContext(oNodes));
	}
	
	// xPath string
	var xPath2s = function(oNodes, sXPath){
		if(oNodes != null){
			var result = xpathParse(sXPath).evaluate(new ExprContext(oNodes));
			if(result.booleanValue() == true){
				var collect = "";
				for(var t=0; t<result.value.length; t++){
					var nodesCheck = result.value[t].childNodes;
					if(nodesCheck.length == 1 && nodesCheck[0].nodeType >= 2 && nodesCheck[0].nodeType <= 4) collect += result.stringValue();
					else collect += xmlText( result.value[t] );
				}
				return collect;
			} else return false;
		} else return false;
	}
}

// shorter version of document.getElementById
var docId = function(x){
	var result = document.getElementById(x);
	if(result == null) return false;
	else return result;
}

// get vars from document.location
var getVars = function(url){
	if(typeof(url) == "undefined") url = window.location.href;
	var gets = new Object();
	try{ var arr = url.split('?')[1].split('&'); } catch(e){ return false };
	for(var t=0; t<arr.length; t++){
		var itm = arr[t].split('=');
		gets[itm[0]] = itm[1];
	}
	return gets;
}

// vars and values to get variables
var setGetVars = function(url, array, slot){
	// strip old get vars but reinsert if not in array
	var oldGets = getVars(url);
	var newUrl = url.split('?')[0];
	for(var g in oldGets){
		if(typeof(array[g]) == "undefined" && g != "slot") array[g] = oldGets[g];
	}
	// append the get vars from array
	for(var t in array){ newUrl += ((newUrl.indexOf("?")>-1)?"&":"?") + t + "=" + array[t]; }
	// append new slot
	if(slot == true) newUrl += ((newUrl.indexOf("?")>-1)?"&slot=":"?slot=") + new Date().getTime().toString().substr(6);
	return newUrl;
}

//vars and values to get variables
var removeGetVars = function(url, array, slot){
	// strip old get vars but reinsert if not in array
	var oldGets = getVars(url);
	var remaining = new Object();
	var newUrl = url.split('?')[0];
	for(var g in oldGets){
		if(typeof(array[g]) == "undefined" && g != "slot") remaining[g] = oldGets[g];
	}
	// append remaining get vars
	for(var t in remaining){ newUrl += ((newUrl.indexOf("?")>-1)?"&":"?") + t + "=" + remaining[t]; }
	// append new slot
	if(slot == true) newUrl += ((newUrl.indexOf("?")>-1)?"&slot=":"?slot=") + new Date().getTime().toString().substr(6);
	return newUrl;
}

// check if path is absolute
var isAbsolutePath = function(path){ return (/:/.test(path)) }

// get direct node childs by tagname
var getChildElementsByTagName = function(src, tagName){
	var collection = new Array();
	var childs = src.childNodes;
	for(var xl=0; xl<childs.length; xl++) if(childs[xl].nodeName == tagName) collection.push(childs[xl]);
	return collection;
}

// direct node childs by classname
var getChildsByClassName = function(src, className){
	var collection = new Array();
	var childs = src.childNodes;
	for(var xl=0; xl<childs.length; xl++) if(childs[xl].className == className) collection.push(childs[xl]);
	return collection;
}

// elements by attribute name
var getElementsByAttribute = function(src, attName){
	var collection = new Array(); var tgs = src.getElementsByTagName('*');
	for(var t=0; t<tgs.length; t++) if(tgs[t].getAttribute(attName)) collection.push(tgs[t]);
	return collection;
}

// gets elements by classname
function getByClassname(needle){
	var nodes = document.getElementsByTagName('*');
	var res = new Array();
	for(var i = 0, j = 0; i < nodes.length; i++){
		var c = ' ' + nodes[i].className + ' ';
		if(c.indexOf(' ' + needle + ' ') != -1) res[j++] = nodes[i];
	}
	return res;
}

// url encoding
var URLEncode = function(clearString){
	var output = '';
	var x = 0;
	clearString = clearString.toString();
	var regex = /(^[a-zA-Z0-9_.]*)/;
	while (x < clearString.length) {
		var match = regex.exec(clearString.substr(x));
		if (match != null && match.length > 1 && match[1] != ''){
			output += match[1];
			x += match[1].length;
		} else {
			if (clearString[x] == ' ') output += '+';
			else {
				var charCode = clearString.charCodeAt(x);
				var hexVal = charCode.toString(16);
				output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
			}
			x++;
		}
	}
	return output;
}

// document new node
var docNode = function(targetNode, element){
	if(!element) return false;
	var node = document.createElement(element);
	var insert = "after";
	for(var t=2; t<arguments.length; t=t+2){
		if(browser.isIE){
			arguments[t] = arguments[t].toLowerCase();
			switch(arguments[t]){
				case "class":
					node.setAttribute('className', arguments[t+1]);
					break;
				case "style":
					var styles = arguments[t+1].split(" ").join("").split(";");
					if(styles[styles.length - 1] == "") styles.pop();
					for(var s=0; s<styles.length; s++){
						var style = styles[s].split(":");
						node.style[style[0]] = style[1];
					}
					break;
				case "onclick":
					node[arguments[t]] = eval("new Function('" + arguments[t+1] + "')");
					break;
				case "onmouseover":
					node[arguments[t]] = eval("new Function('" + arguments[t+1] + "')");
					break;
				case "onmouseout":
					node[arguments[t]] = eval("new Function('" + arguments[t+1] + "')");
					break;
				case "onchange":
					node[arguments[t]] = eval("new Function('" + arguments[t+1] + "')");
					break;
				case "insert":
					insert = arguments[t+1];
					break;
				default:
					node.setAttribute(arguments[t], arguments[t+1]);
					break;
			}
		}
		else if(arguments[t] == "insert") insert = arguments[t+1];
		else node.setAttribute(arguments[t], arguments[t+1]);
	}
	if(typeof(targetNode) == "string") targetNode = docId(targetNode);
	if(typeof(targetNode) == "undefined") return false;
	if(insert == "before") targetNode.insertBefore(node, targetNode.firstChild);
	else if(!isNaN(insert)) targetNode.insertBefore(node, targetNode.childNodes[parseInt(insert)]);
	else targetNode.appendChild(node);
	return node;
}

// insert html with whitespace:
var xtml = function(tg, str, replace, preserveWhitespace){
	if(typeof(tg) == "string") tg = docId(tg);
	if(typeof(tg) == "object"){
		if(preserveWhitespace == true){
			// preserve whitespace but still wrap text
			if(browser.isIE){
				tg.style.wordWrap = "break-word";
				tg.style.whiteSpace = "pre";
			} else tg.style.whiteSpace = "-moz-pre-wrap";
		}
		if(tg != null){
			if(replace == true) tg.innerHTML = str;
			else tg.innerHTML += str;
			return true;
		} else return false;
	} else return false;
}

// change css attributes
var changecss = function(theClass, element, value){
	var cssRules;
 	if(document.all) cssRules = 'rules';
	else if(document.getElementById) cssRules = 'cssRules';
	for(var S = 0; S < document.styleSheets.length; S++){
		for(var R = 0; R < document.styleSheets[S][cssRules].length; R++) if(document.styleSheets[S][cssRules][R].selectorText == theClass) document.styleSheets[S][cssRules][R].style[element] = value;
	}	
}

// CSS Browser Selector v0.2.9, http://rafael.adm.br
var css_browser_selector = function() {var ua=navigator.userAgent.toLowerCase(),is=function(t){return ua.indexOf(t) != -1;},h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera\s(\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('chrome')?'chrome webkit safari':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js'; h.className += h.className?' '+c:c;}();

// dynamic load css and js file with callback on load
var loadScript = function(path, callBack, slot){
	var fileType = path.split('.').pop();
	// cache slot
	if(slot == true) path += ((path.indexOf("?")>-1)?"&slot=":"?slot=") + new Date().getTime().toString().substr(6);
	// type switch
	if(fileType == 'css'){
		var nNode = document.createElement('link');
		nNode.type = 'text/css';
		nNode.rel = 'stylesheet';
		nNode.href = path;
	} else if(fileType == 'js'){
		var nNode = document.createElement('script');
		nNode.type = 'text/javascript';
		nNode.language = 'JavaScript';
		nNode.src = path;
	}
	// add script tag to doc head
	var ready = function(){
		var callType = typeof(callBack);
		if(callType == "string") eval(callBack)(nNode);
		else if(callType == "function") callBack(nNode);
	}
	nNode.onload = function(){ ready(); }
	nNode.onreadystatechange = function(){ if(nNode.readyState == "loaded") ready(); }
	document.getElementsByTagName("head")[0].appendChild(nNode);
}

// deselect txt
var deselect = function(){
	if(browser.isIE) document.selection.empty();
	else window.getSelection().removeAllRanges();
}

// get flash object
function getFlashMovieObject(movieName){
	if(window.document[movieName]) return window.document[movieName];
	if(navigator.appName.indexOf("Microsoft Internet") == -1){
		if(document.embeds && document.embeds[movieName]) return document.embeds[movieName];
	} else return document.getElementById(movieName);
}

var sendDataToFlashMovie = function(swfName, rootVar, newValue){
	getFlashMovieObject(swfName).SetVariable("/:" + rootVar, newValue);
}

var receiveDataFromFlashMovie = function(swfName, rootVar){
	return getFlashMovieObject(swfName).GetVariable("/:" + rootVar);
}

var flashMovieResponse = function(movieName){
	var flashMovie = getFlashMovieObject(movieName);
	if(typeof(flashMovie.GetVariable) != 'function') return false;
	else return true;
}

// change location
var myLoc = function(url){window.location.href = url;}
var newLoc = function(url){window.open(url);}

// find real object position
var findPos = function(obj){
	var curleft = curtop = 0;
	if (obj.offsetParent){
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent){
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

// get browser viewport size
var winSize = function(){
	var myWidth = 0, myHeight = 0;
	if(typeof(window.innerWidth) == 'number'){
		// Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		// IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if(document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		// IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return new Object({'width':myWidth,'height':myHeight});
}

// set div opacity
var setOpacity = function(opacity, object){
	if(typeof(object) == 'object') object = object.style;
	else object = document.getElementById(object).style;
	// If it's 100, set it to 99 for Firefox.
	if(navigator.userAgent.indexOf("Firefox") != -1) if(opacity == 100) opacity = 99.999;
	// Multi-browser opacity setting
	// IE/Win
	object.filter = "alpha(opacity=" + opacity + ")";
	// Safari 1.1 or lower, Konqueror
	object.KhtmlOpacity = (opacity / 100);
	// Older Mozilla, Firefox
	object.MozOpacity = (opacity / 100);
	// Safari 1.2, Firefox, Mozilla
	object.opacity = (opacity / 100);
}

// in array
var inArray = function(arr, obj){
	for(var t  in arr) if(arr[t] == obj) return true;
	return false;
}

// make array unique
var arrayUnique = function(src){
	var uniqueArr = new Array();
	for(var origKey in src){
		valueExists = false;
		for(var uniqueKey in uniqueArr){
			if(uniqueArr[uniqueKey] == src[origKey]){
				valueExists = true;
			}
		}
		if(!valueExists){
			uniqueArr.push(src[origKey]);
		}
	}
	return uniqueArr;
}

// message pane
var msg = function(src){
	if(src == false) document.body.removeChild(docId('msgPane'));
	else{
		if(docId('msgPane')) document.body.removeChild(docId('msgPane'));
		document.body.innerHTML += "<div id='msgPane' onclick='msg(0)' style='position:absolute; border-style:solid; border-width:1px; border-color:#cdcdcd; background:#efefef; padding:3px; font-size:12px; color:#666;'> </div>";
		var pane = docId('msgPane');
		pane.innerHTML = src;
		var wSize = winSize();
		pane.style.left = (wSize.width - pane.offsetWidth) / 2 + 'px';
		pane.style.top = (wSize.height - pane.offsetHeight) / 2 + 'px';
		setOpacity(92, pane);
	}
}

// apply PNG background
var myOpacityObject = function (divTarget, strPath){
	this.path = strPath + ".png";
	this.layerObject = divTarget;
	this.setBackground = function(){ // AlphaImageLoader for IE5 and 6, css for others
		if(!this.layerObject.getAttribute('id')) this.layerObject.setAttribute('id', 'png' + pngCount); pngCount++; // give each png layer unique id
		if(pngAlphaFilter) this.layerObject.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + this.path + '", sizingMethod="scale")';
		else this.layerObject.style.backgroundImage = 'url(' + this.path + ')';
	}
}
// sets myOpacityObject right away
var alphaBg = function(tg, img){ return new myOpacityObject(tg, img).setBackground(); }

// apply PNG background to all elements with bg attribute
var setBgChilds = function(tg){
	if(typeof(tg) == "string") tg = docId(tg);
	// set self
	if(typeof(tg.getAttribute("bg")) != "undefined") alphaBg(tg, tg.getAttribute("bg"));
	// set childs
	var nodes = getElementsByAttribute(tg, "bg");
	for(var t=0; t<nodes.length; t++){ alphaBg(nodes[t], nodes[t].getAttribute("bg")); };
}
// alpha background with docId
var get2SetBg = function(idName, bgUrl){
	var obj = docId(idName);
	var tmp = new myOpacityObject(obj, bgUrl).setBackground();
	return obj;
}

// map png images from images array
function updatePng(){
	for(var t in pngLib){
		var tgs = getByClassname(t);
		for(var y in tgs){
			var iAm = tgs[y];			
			var objMyImg = new myOpacityObject(iAm, pngLib[t]);
			objMyImg.setBackground();
		}
	}
}

// find all existing rct attributes in document
var setRctChilds = function(tg, centerBg){
	if(typeof(centerBg) == "undefined") centerBg = true;
	if(typeof(tg) == "string") tg = docId(tg);
	// set self
	if(typeof(tg.getAttribute("rct")) != "undefined") setRct(tg, centerBg);
	// set childs
	var nodes = getElementsByAttribute(tg, "rct");
	for(var t=0; t<nodes.length; t++){ setRct(nodes[t], centerBg); };
}

var setRct = function(tg, centerBg){
	if(typeof(tg) == "string") tg = docId(tg);
	var rctPath = tg.getAttribute('rct');
	var rctStroke = tg.getAttribute('rctstroke');
	var oldPath = tg.getAttribute('rctprev');
	if(rctPath && rctStroke){
		var tW = tg.offsetWidth - 1; if(tW < 0) tW = 0;
		var tH = tg.offsetHeight;
		var rctStroke = rctStroke.split(',');
		var strokeL = rctStroke[0];
		var strokeR = rctStroke[1];
		var strokeT = rctStroke[2];
		var strokeB = rctStroke[3];
		// if new rct generate bg divs
		if(rctPath != oldPath){
			// first delete existing rcts
			var chds = docPath(tg, "div@rctype");
			for(var l in chds) tg.removeChild(chds[l]);
			// build bg divs
			if(strokeL>0 && strokeT>0) var tl = docNode(tg, 'div', 'insert', 'before', 'rctype', 'tl', 'style', 'width:' + strokeL + 'px; height:' + strokeT + 'px; top:' + (0 - strokeT) + 'px; left:' + (0 - strokeL) + 'px; position:absolute');
			if(strokeT>0) var tm = docNode(tg, 'div', 'insert', 'before', 'rctype', 'tm', 'style', 'width:' + tW + 'px; height:' + strokeT + 'px; top:' + (0 - strokeT) + 'px; left:' + 0 + 'px; position:absolute');
			if(strokeR>0 && strokeT>0) var tr = docNode(tg, 'div', 'insert', 'before', 'rctype', 'tr', 'style', 'width:' + strokeR + 'px; height:' + strokeT + 'px; top:' + (0 - strokeT) + 'px; left:' + tW + 'px; position:absolute');
			if(strokeL>0) var ml = docNode(tg, 'div', 'insert', 'before', 'rctype', 'ml', 'style', 'width:' + strokeL + 'px; height:' + tH + 'px; top:' + 0 + 'px; left:' + (0 - strokeL) + 'px; position:absolute');
			if(strokeR>0) var mr = docNode(tg, 'div', 'insert', 'before', 'rctype', 'mr', 'style', 'width:' + strokeR + 'px; height:' + tH + 'px; top:' + 0 + 'px; left:' + tW + 'px; position:absolute');
			if(strokeL>0 && strokeB>0) var bl = docNode(tg, 'div', 'insert', 'before', 'rctype', 'bl', 'style', 'width:' + strokeL + 'px; height:' + strokeB + 'px; top:' + tH + 'px; left:' + (0 - strokeL) + 'px; position:absolute');
			if(strokeB>0) var bm = docNode(tg, 'div', 'insert', 'before', 'rctype', 'bm', 'style', 'width:' + tW + 'px; height:' + strokeB + 'px; top:' + tH + 'px; left:' + 0 + 'px; position:absolute');
			if(strokeR>0 && strokeB>0) var br = docNode(tg, 'div', 'insert', 'before', 'rctype', 'br', 'style', 'width:' + strokeR + 'px; height:' + strokeB + 'px; top:' + tH + 'px; left:' + tW + 'px; position:absolute');
			// set background imgs
			var eml = docPath(tg, "div@rctype");
			for(var t in eml){
				eml[t].style.fontSize = "0px";
				alphaBg(eml[t], rctPath + '/' + eml[t].getAttribute('rctype'));
			}
			// set center background
			if(centerBg == true) tg.style.backgroundImage = "url(" + rctPath + "/mm.png)";
			// remember previous path
			tg.setAttribute('rctprev', rctPath);
		}
		// else justmove elements to new positions
		else{
			var eml = docPath(tg, "div@rctype");
			for(var t in eml){
				var em = eml[t];
				switch(em.getAttribute('rctype')){
					case 'tm': em.style.width = tW + 'px'; break;
					case 'tr': em.style.left = tW + 'px'; break;
					case 'ml': em.style.height = tH + 'px'; break;
					case 'mr': em.style.height = tH + 'px'; em.style.left = tW + 'px'; break;
					case 'bl': em.style.top = tH + 'px'; break;
					case 'bm': em.style.top = tH + 'px'; em.style.width = tW + 'px'; break;
					case 'br': em.style.top = tH + 'px'; em.style.left = tW + 'px'; break;
				}
			}
		}
	}
}

// place object 'next' to object by 'placer' attribute
var placer = function(tg){
	var task = tg.getAttribute("placer").split(":");
	if(task.length == 3){
		var obj = document.getElementById(task[0]);
		task[2] = parseInt(task[2]);
		switch(task[1]){
			case 'left':
				tg.style.left = obj.offsetLeft - tg.offsetWidth - task[2] + 'px';
				tg.style.top = obj.offsetTop + 'px';
				break;
			case 'right':
				tg.style.left = obj.offsetLeft + obj.offsetWidth + task[2] + 'px';
				tg.style.top = obj.offsetTop + 'px';
				break;
			case 'top':
				tg.style.left = obj.offsetLeft + 'px';
				tg.style.top = obj.offsetTop - tg.offsetHeight - task[2] + 'px';
				break;
			case 'bottom':
				tg.style.left = obj.offsetLeft + 'px';
				tg.style.top = obj.offsetTop + obj.offsetHeight + task[2] + 'px';
				break;
		}
	}
}

// cross browser xpath(ish) in html document
var docPath = function(startNode, action){
	if(typeof(startNode) == "string") startNode = docId(startNode);
	if(typeof(startNode) == "undefined") return false;
	var docPathArray = function(node, pathLeft){
		var result = new Array();
		var pathStep = pathLeft.shift();
		var nodes = node.childNodes;
		for(var t=0; t<nodes.length; t++){
			if(nodes[t].nodeType == 1){
				// node path
				if( (nodes[t].tagName.toLowerCase() == pathStep || pathStep == '*') || (nodes[t].tagName.toLowerCase() == pathStep.split("@")[0] && nodes[t].attributes[pathStep.split("@")[1]]) ){
					// store for recursive call
					if(pathLeft.length > 0){
						var tmp = docPathArray(nodes[t], [].concat(pathLeft));
						// if found something
						if(tmp.length > 0) result.push(tmp);
					}
					// result
					else basket.push(nodes[t]);
				}
			}
		}
		return result;
	}
	var basket = new Array();
	docPathArray(startNode, action.toLowerCase().split('/'));
	return basket;
}

// Count loaded alpha png's
var pngCount = 0; 
// ie7 displays alpha without activeX
if(browser.isIE && browser.versionMinor < 7) var pngAlphaFilter = true;

// drag div with drag=true, to activate: document.onmousedown = selectmouse;
function selectmouse(e){
	var fobj = browser.isIE ? event.srcElement : e.target;
	if(fobj.tagName.toLowerCase() == 'div'){
		try{
			while(fobj.tagName != "body" && fobj.getAttribute('drag') != 'true') fobj = browser.isIE ? fobj.parentElement : fobj.parentNode;
			if(fobj.getAttribute('drag') == 'true'){
				var tx = parseInt(fobj.style.left + 0, 10);
				var ty = parseInt(fobj.style.top + 0, 10);
				var x = browser.isIE ? event.clientX : e.clientX;
				var y = browser.isIE ? event.clientY : e.clientY;
				onTop(fobj);
				document.onmouseup = function(){ document.onmousemove = null; document.onmouseup = null; }
				document.onmousemove = function(e){
					fobj.style.left = browser.isIE ? tx + event.clientX - x : tx + e.clientX - x;
					fobj.style.top = browser.isIE ? ty + event.clientY - y : ty + e.clientY - y;
					if(fobj.getAttribute('dragdo')) eval(dobj.getAttribute('dragdo'))(fobj);
				}
			} else if(fobj.getAttribute('pressdo')) eval(fobj.getAttribute('pressdo'))(fobj, e);
		} catch(e){};
	}
}

// eval string on next time mouse button up
var mouseUpOnceMinimum = 200;
var mouseUpOnce = function(todo){
	mouseUpOnceAction = todo;
	mouseUpOnceStart = new Date().getTime();
	document.onmouseup = function(){
		var upTime = new Date().getTime();
		var duration = upTime - mouseUpOnceStart;
		document.onmouseup = null;
		if(duration < mouseUpOnceMinimum) setTimeout("if(typeof(mouseUpOnceAction) != 'undefined'){ eval(mouseUpOnceAction); delete mouseUpOnceAction;}", mouseUpOnceMinimum - duration);
		else{
			eval(mouseUpOnceAction);
			delete mouseUpOnceAction;
			delete mouseUpOnceStart;
		}
	}
}

// make node lastChild (in html visual on top :-)
var onTop = function(tg){
	var Parent = tg.parentNode;
	if(Parent.lastChild != tg) Parent.appendChild( Parent.removeChild(tg) );
}

// make node firstChild
var onBottom = function(tg){
	var Parent = tg.parentNode;
	if(Parent.firstChild != tg) Parent.appendChild( Parent.removeChild(tg) );
}

// Browser-neutral XMLHttpRequest object
var getHTTPObject = function(){
	var xmlhttp;
	if(browser.isWin && browser.isIE){
		try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){
			try{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }catch(E){ xmlhttp = false; }
		}
	} else if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
		try{ xmlhttp = new XMLHttpRequest(); }catch(e){ xmlhttp = false; }
	}
	return xmlhttp;
}

// async load files from same domain
var load = function(url, callBack, strict, posts, asynchronous, slot){
	// asynchronous or not
	if(typeof(asynchronous) == "undefined") asynchronous = true;
	if(asynchronous != true) asynchronous = false;
	// cache slot
	if(slot == true) url += ((url.indexOf("?")>-1)?"&slot=":"?slot=") + new Date().getTime().toString().substr(6);
	// http object
	var httpReq = getHTTPObject();
	if(asynchronous){
		httpReq.onreadystatechange = function(){
			if(httpReq.readyState == 4){
				// FF or IE
				if(httpReq.responseXML == null || httpReq.responseXML.firstChild == null){
					if(strict == "strictXml"){
						rec = false;
						if(browser.isIE){
							// for loading local files with IE
							rec = new ActiveXObject("Microsoft.XMLDOM");
							rec.loadXML(httpReq.responseText);
						}
					} else var rec = httpReq.responseText;
				} else var rec = httpReq.responseXML;
				(typeof(callBack) == "string") ? eval(callBack)(rec) : callBack(rec);
			}
		}
	}
	// get or post
	if(isArray(posts)){
		var postData = "";
		for(var i in posts) postData += encodeURIComponent(i) + "=" + encodeURIComponent(posts[i]) + "&";
		if(postData.lengh > 0) postData = postData.slice(0, postData.length - 1);
		httpReq.open("POST", url, asynchronous);
		httpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		httpReq.setRequestHeader("Content-length", postData.length);
		httpReq.setRequestHeader("Connection", "close");
		httpReq.send(postData);
	} else{
		httpReq.open("GET", url, asynchronous);
		httpReq.send(null);
	}
	// response for synchronious calls
	if(!asynchronous){
		if(strict == "strictXml") rec = httpReq.responseXML;
		else rec = httpReq.responseText;
		if(typeof(callBack) == "string") eval(callBack)(rec);
		else if(typeof(callBack) == "function") callBack(rec);
		else return rec;
	}
}

// embedding media player object
var multiMedia = function(tg, url, width, height, playOnLoad){
	if(typeof(tg) == "string"){tg = docId(tg);};
	// make unique id for object
	var objId = "media" + new Date().getTime().toString().substr(6);
	// prepare
	if(!width || width == '') var width = tg.offsetWidth;
	if(!height || height == '') var height = tg.offsetHeight;
	if(playOnLoad == true) playOnLoad = 1;
	else playOnLoad = 0;

	// remove previous media objects
	// KAE 6/10/2008 : Emptying div that is displaying the element, doing a
	// manual stop on the presentation to force shutdown of the mediaplayer
	var childs = tg.childNodes;
	if(childs){
		for(t=0; t<childs.length; t++){
			var nodeNm = childs[t].nodeName.toLowerCase();
		}
	}
	// alert("enabled: " + docId(objId).controls.enabled);
	tg.innerHTML = "";
	// alert("test:"+ document.getElementById('audioDiv').innerHTML);


	// according to media type
	if(url) var ext = url.substring(url.length -4);
	if(ext == ".mp3"){
		embedFlash(width, height, "swf/media.swf?swfMediaUrl=" + url, tg, objId);
		// controls
		var ctrl = new Object();
		// controls
		ctrl.stop = function(){getFlashMovieObject(objId).extIntStop();};
		ctrl.pause = function(){getFlashMovieObject(objId).extIntPause();};
		ctrl.resume = function(){getFlashMovieObject(objId).extIntResume();};
		ctrl.time = function(){return getFlashMovieObject(objId).extIntTime();};
		ctrl.setTime = function(to){getFlashMovieObject(objId).extIntSetTime(to);};
		ctrl.setVolume = function(to){getFlashMovieObject(objId).extIntSetVolume(to);};
		ctrl.duration = function(){return getFlashMovieObject(objId).extIntDuration();};
	} else if(ext == ".m4x" || ext == ".mp4"){
		// ibm m4x player
		var javaErrorString = "Please enable Java (JRE) for this web browser...";
		var appletFile = "mp4Applet1.2.9";
		tg.innerHTML += '<applet id="' + objId + '" width="' + width + '" height="' + height + '" code="M4Applet.class" codebase="./java" id="m4player" name="m4player" alt="' + javaErrorString + '" archive="' + appletFile + '.jar"><param name="CABBASE" value="' + appletFile + '.cab"><param name="url" value="' + url + '"><param name="panel" value="none"><param name="atDuration" value="Stop"></applet>';
		var pObj = document.getElementById(objId);
		// controls
		var ctrl = new Object();
		ctrl.pause = function(){pObj.player_pause();};
		ctrl.resume = function(){pObj.player_resume();};
		ctrl.time = function(){return pObj.player_getTime();};
		ctrl.duration = function(){return pObj.player_getDuration();};
	} else if(url){
			// windows mediaplayer object
			if(browser.isIE){
				tg.innerHTML += "<object id='" + objId + "' width='" + width + "' height='" + height + "' classid=clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6><param NAME='autostart' VALUE='0'><param name='showStatusbar' value='0'/><param name='showDisplay' value='0'/><param name='ShowControls' value='0'/><param name='uiMode' value='none'/><param name='stretchToFit' value='true'/><param name='url' value='" + url + "'/><param name='SendPlayStateChangeEvents' value='True'/></object><script FOR='" + objId + "' EVENT='ScriptCommand(bstrType, bstrParam)' LANGUAGE='Jscript'>wmevent(bstrType, bstrParam);</script><script for='" + objId + "' event='playStateChange(NewState)' language='jscript' type='text/jscript'>wmstate(NewState);</script>";
				// start playing
				if(playOnLoad != false) document[objId].controls.play();
			} else{
				tg.innerHTML += "<object id='" + objId + "' type='application/x-ms-wmp' data='" + url + "' width='" + width + "' height='" + height + "'></object><script FOR='" + objId + "' EVENT='ScriptCommand(bstrType, bstrParam)' LANGUAGE='Jscript'>wmevent(bstrType, bstrParam);</script><script for='" + objId + "' event='playStateChange(NewState)' language='jscript' type='text/jscript'>wmstate(NewState);</script>";

				var embd = document.createElement("embed");
				embd.setAttribute("width", width);
				embd.setAttribute("height", height);
				embd.setAttribute("autostart", playOnLoad);
				embd.setAttribute("showStatusbar", 0);
				embd.setAttribute("showDisplay", 0);
				embd.setAttribute("showControls", 0);
				embd.setAttribute("uiMode", "none");
				embd.setAttribute("src", url);
				// embd.setAttribute("type", "application/x-mplayer2");
				embd.setAttribute("SendPlayStateChangeEvents", "True");
				var wmpObj = document.getElementById(objId);
				wmpObj.appendChild(embd);
				// start playing
				try{wmpObj.controls.play();}catch(e){if(browser.isWin) setTimeout("infoPane('help', 'configure1')", 300);};
			}

			// controls
			var ctrl = new Object();
			ctrl.stop = function(){docId(Player.objectId).controls.stop();};
			ctrl.pause = function(){docId(Player.objectId).controls.pause();};
			ctrl.resume = function(){docId(Player.objectId).controls.play();};
			ctrl.time = function(){return Math.round(docId(Player.objectId).controls.currentPosition * 1000);};
			ctrl.setTime = function(to){docId(Player.objectId).controls.currentPosition = Math.round(to / 1000);};
			ctrl.setVolume = function(to){docId(Player.objectId).settings.volume = to;};
			ctrl.duration = function(){return Math.round(docId(Player.objectId).currentMedia.duration * 1000);};
			ctrl.close = function(){docId(Player.objectId).close();}
	}

	// reference to player by id
	if(typeof(ctrl) != "undefined") ctrl.objectId = objId;
	return ctrl;
}

var embedFlash = function(flashWidth, flashHeight, flashMovie, target, id){
	if(!id) id = "swf" + (new Date().getTime());
	target.innerHTML += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" '
	+ 'width="'+flashWidth+'" height="'+flashHeight+'" id="'+id+'" align="middle">'
	+ '<param name="allowScriptAccess" value="sameDomain" />'
	+ '<param name="movie" value="'+flashMovie+'" />'
	+ '<param name="quality" value="best" />'
	+ '<embed src="'+flashMovie+'" quality="best" '
	+ 'width="'+flashWidth+'" height="'+flashHeight+'" name="'+id+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
}

// install a firefox plugin
var installPlugin = function(path){
	plugin_xpi = {'WMP ActiveX plugin': path};
	InstallTrigger.install(plugin_xpi);
}

// true if object is an array
var isArray = function(obj){
	if(obj != null){
		if(obj.constructor.toString().indexOf("Array") == -1) return false;
		else return true;
	} else return false;
}

// set cookies
var setCookie = function(cookieName, cookieValue, nDays){
	var today = new Date();
	var expire = new Date();
	if(nDays == null || nDays == 0) nDays = 1;
	expire.setTime(today.getTime() + 3600000 * 24 * nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires=" + expire.toGMTString();
}

// get cookies
var getCookie = function(c_name){
	if(document.cookie.length > 0){
		var c_start = document.cookie.indexOf(c_name + "=");
		if(c_start != -1){
			c_start = c_start + c_name.length + 1; 
			var c_end = document.cookie.indexOf(";", c_start);
			if(c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} else return false;
	} else return false;
}

// render tabset
var renderTabSet = function(structure, firstLevelTg, secondLevelTg, contentTg, stringsData, libData){
	if(typeof(tabSets) == "undefined") tabSets = new Object();
	tabSets[firstLevelTg] = new Object();
	tabSets[firstLevelTg].tabs = new Array();
	tabSets[firstLevelTg].secondLevelTg = secondLevelTg;
	tabSets[firstLevelTg].contentTg = contentTg;
	tabSets[firstLevelTg].strings = stringsData;
	tabSets[firstLevelTg].lib = libData;
	var tabs = xPath(structure, "tab");
	for(var t=0; t<tabs.length; t++){
		var newTab = xPath(tabs[t], "div")[0];
		newTab.setAttribute("tabId", t);
		newTab.setAttribute("tabGroup", firstLevelTg);
		if(t == 0) newTab.setAttribute("id", firstLevelTg + "Default");
		tabSets[firstLevelTg].tabs[t] = xPath(tabs[t], "item");
		xtml(firstLevelTg, xml2str(newTab), false, false);
	}
	// activate first tab
	tab1Switch(docId(firstLevelTg + "Default"));
}
// switch to this tab1 item
var tab1Switch = function(tg){
	if(tg.className == "tab1Idle"){
		tabBgSwitch(tg, "tab1");
		var tabSet = tabSets[tg.getAttribute("tabGroup")];
		var secondTabs = tabSet.tabs[tg.getAttribute("tabId")];
		var secondTg = tabSet.secondLevelTg;
		var stringsData = tabSet.strings;
		var libData = tabSet.lib;
		// remove old tab2's
		tgDivs = docPath(secondTg, "div");
		for(var t in tgDivs){
			tgDivs[t].parentNode.removeChild(tgDivs[t]);
		}
		// render new tab2's
		for(var t=0;  t<secondTabs.length; t++){
			var newTab = xPath(secondTabs[t], "div")[0];
			newTab.setAttribute("id", secondTg + t);
			newTab.setAttribute("tabId", t);
			newTab.setAttribute("tabGroup", tg.getAttribute("tabGroup"));
			newTab.setAttribute("level1", tg.getAttribute("tabId"));
			xtml(secondTg, xml2str(newTab), false, false);
			if(t == secondTabs.length - 1) docId(secondTg + t).style.borderRightStyle = "none";
		}
		// update document strings
		setAllLanguageStrings(stringsData);
		// activate first tab level 2
		tab2Switch(docId(secondTg + "0"));
	}
}
// switch to this tab2 item
var tab2Switch = function(tg){
	if(tg.className == "tab2Idle"){
		tabBgSwitch(tg, "tab2");
		// render tab's content
		var tabSet = tabSets[tg.getAttribute("tabGroup")];
		var stringsData = tabSet.strings;
		var libData = tabSet.lib;
		// second level
		var secondTabs = tabSets[tg.getAttribute("tabGroup")].tabs[tg.getAttribute("level1")];
		var tabXml = secondTabs[parseInt(tg.getAttribute("tabId"))];
		var contentType = xPath2s(tabXml, "content/@type");
		var scriptType = xPath2s(tabXml, "script/@type");
		// add content
		if(contentType == "path") xtml(tabSets[tg.getAttribute("tabGroup")].contentTg, xPath2s(libData,  xPath2s(tabXml, "content")), true, false);
		else if(contentType == "source") xtml(tabSets[tg.getAttribute("tabGroup")].contentTg,  xPath2s(tabXml, "content"), true, false);
		// run script
		if(scriptType == "path") eval( xPath2s(libData, xPath2s(tabXml, "script")) );
		else if(scriptType == "source") eval( xPath2s(tabXml, "script") );
		//alert( xPath2s(tabXml, "script"));
	}
}
// switch tab backgrounds
var tabBgSwitch = function(tg, tabClass){
	var itm = docPath(tg.parentNode, "div");
	for(var t=0; t<itm.length; t++){
		if(itm[t].className){
			if(itm[t].className.indexOf("tab") > -1){
				if(itm[t] == tg) itm[t].className = tabClass + "Active";
				else itm[t].className = tabClass + "Idle";
			}
		}
	}
}

// string ID + lang code to text string
var getLanguageString = function(stringsCollection, name){
	var s = xPath2s(stringsCollection, "/strings/s[@id='" + name + "']");
	if(s) return s;
	else { msg("getLanguageString: id not defined, id name: " + name); return "?"; }
}
// put all strings in font tags with string id
var setAllLanguageStrings = function(stringsObject){
	var strings = document.getElementsByTagName("font");
	for(var t=0; t<strings.length; t++) xtml(strings[t], getLanguageString(stringsObject, strings[t].getAttribute("id")), true, true);
}

//DEPRECIATED, use getLanguageString bow
var setSpanStrings = function(startNode, stringsObject){
	var strings = startNode.getElementsByTagName("span");
	for(var t=0; t<strings.length; t++){
		if(strings[t].getAttribute("string")){
			var newString = getLanguageString(stringsObject, strings[t].getAttribute("string"));
			var newTxtNode = document.createTextNode( newString );
			removeChilds(strings[t]);
			strings[t].appendChild(newTxtNode);
		}
	}
}

// http://ejohn.org/projects/flexible-javascript-events
function addEvent( obj, type, fn ){
	if(obj.attachEvent){
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
		obj.attachEvent( 'on'+type, obj[type+fn] );
	} else obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
	if(obj.detachEvent){
		obj.detachEvent( 'on'+type, obj[type+fn] );
		obj[type+fn] = null;
	} else obj.removeEventListener( type, fn, false );
}

//remove all child nodes
var removeChilds = function(holder){
	if(typeof(holder) == "object") while(holder.hasChildNodes()){ holder.removeChild(holder.lastChild); }
	else if(typeof(holder) == "string") { var holder = docId(holder); while(holder.hasChildNodes()){ holder.removeChild(holder.lastChild); } }
}
